#include "TestClass.h"
#include <new>
#include <cstdlib>
#include "MemmoryHandler.h"

using namespace std;


TestClass::TestClass(void)
{
}

TestClass::~TestClass(void)
{
}

void *TestClass::operator new(size_t value, int line, char *file)
{
	void * p = malloc(value);

	bad_alloc ex;
	if (p == NULL)
	{
		throw ex;
	} 
	else
	{
		MemmoryHandler::GetInstance()->registerIntoMemMap(p, value, false, line, file);
	}
	
	return p;
}

void *TestClass::operator new[](size_t value, int line, char *file)
{
	void * p = malloc(value);

	bad_alloc ex;
	if (p == NULL)
	{
		throw ex;
	}
	else
	{
		MemmoryHandler::GetInstance()->registerIntoMemMap(p, value, true, line, file);
	}

	return p;
}

void TestClass::operator delete(void *p, int line, char *file)
{
	free(p);

	MemmoryHandler::GetInstance()->unregisterOfMemMap(p);

}

void TestClass::operator delete[](void *p, int line, char *file)
{
	free(p);

	MemmoryHandler::GetInstance()->unregisterOfMemMap(p);
}